import java.util.Scanner;
import java.util.Stack;

public class work1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("请输入一个十进制数字: ");
        int decimalNumber = scanner.nextInt();

        System.out.print("请输入想要转换为几进制的数字（2, 8, 16）: ");
        int targetBase = scanner.nextInt();

        Stack<Character> stack = new Stack<>();
        while (decimalNumber > 0) {
            int remainder = decimalNumber % targetBase;
            if (remainder < 10) {
                stack.push((char) (remainder + '0'));
            } else {
                stack.push((char) (remainder - 10 + 'A'));
            }
            decimalNumber /= targetBase;
        }

        System.out.println("转换后的结果: ");
        while (!stack.isEmpty()) {
            System.out.print(stack.pop());
        }
    }
}